import dayjs from 'dayjs';

// 导出Excel文件 下载 （文件流）
export const exportToXlsxBlob = ( data: BlobPart, fileName: string,type?:string) => {
  // console.log(data);
  let isType=''
  if(type){
    if(type==='pdf') isType='application/pdf'
  }else{ //xlsx
    isType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  }
  const blob = new Blob([data], { type: isType }) // 拿到
  // 创建一个隐藏的<a>标签来进行下载
  const elink = document.createElement('a');
  const time=dayjs(new Date()).format("YYYY-MM-DD");
  elink.download = `${fileName}-${time}`;
  elink.style.display = 'none'
  elink.href = URL.createObjectURL(blob)
  document.body.appendChild(elink)
  elink.click()
  URL.revokeObjectURL(elink.href)
  document.body.removeChild(elink)
};

